import Vue from 'vue'
import App from './App'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import axioscy from "axios";
axioscy.defaults.baseURL='http://localhost:25006/services'
Vue.prototype.$http=axioscy;
import VueRouter from 'vue-router'
import store from './vuex/store'
import Vuex from 'vuex'
import routes from './routes'
import 'font-awesome/css/font-awesome.min.css'
import  NProgress from  'nprogress'

Vue.use(ElementUI)
Vue.use(VueRouter)
Vue.use(Vuex)

const router = new VueRouter({
  routes
})

// router.beforeEach((to, from, next) => { //路由拦截器
//   //NProgress.start();
//   if (to.path == '/login') {
//     localStorage.removeItem('loginInfo');
//   }
//   let loginInfo = JSON.parse(localStorage.getItem('loginInfo'));
//   if (!loginInfo && to.path != '/login') {
//     next({ path: '/login' })
//   } else {
//     next()
//   }
// })

// //1 使用axios前置拦截器，让所有的请求都携带token
// axioscy.interceptors.request.use(config=>{
//   //携带token
//   let token =  localStorage.getItem("token");
//   if(token){
//     config.headers['token']=token;
//   }
//   return config;
// },error => {
//   Promise.reject(error);
// })

// //2 使用axios后置拦截器，处理没有登录请求
// axioscy.interceptors.response.use(result=>{
//   console.log(result.data+"jjjjjjj");
//   let data = result.data;  // {success:false,message:"noLogin"}
//   // 说明后端返回错误信息是 未登录，那么就要跳转到登录页面
//   if(!data.success && data.message==="noLogin"){
//     router.push({ path: '/login' });
//   }
//   return result;
// },error => {
//   Promise.reject(error);
// })

router.afterEach(transition => {
NProgress.done();
});

new Vue({
  //el: '#app',
  //template: '<App/>',
  router,
  store,
  //components: { App }
  render: h => h(App)
}).$mount('#app')

